
<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>退货记录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script type="text/html" id="indexTpl">
        {{d.LAY_TABLE_INDEX+1}}
    </script>
</head>
<body>
<div class="layui-card">
    <div class="layui-card-body layui-table-body layui-table-main">
        <table class="layui-table layui-form" id="main-table" lay-filter="main-table">
        </table>
    </div>
    <script type="text/html" id="toolbarDemo">
        <button class="layui-btn" lay-event="add"><i class="layui-icon"></i>添加</button>
        <div class="layui-inline layui-show-xs-block">
            <input type="text" class="layui-input" name="param" id="param" placeholder="根据药品名称查询" autocomplete="off">
        </div>
        <div class="layui-inline layui-show-xs-block">
        <button class="layui-btn" lay-event="querySearch"><i class="layui-icon">&#xe615;</i></button>
        </div>
    </script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
</div>
</body>
<script>
    layui.use(['table','form'], function(){
        var $ = layui.$;
        var table = layui.table;
        table.render({
            elem: '#main-table',
            height: 550,
            url: '/returngoods/returngoodsQueryPage',
            method: 'POST',
            page: true,
            id: 'table-load',
            toolbar: '#toolbarDemo',
            cols: [
                [
                    {title: '序号', templet: '#indexTpl', align: 'center', width: 60},
                    {field: 'dname', title: '药品名称', align: 'left', width: 150},
                    {field: 'count', title: '数量', align: 'left', width: 100},
                    {field: 'reason', title: '退货原因', align: 'left', width: 220},
                    {field: 'total', title: '总金额', align: 'left', width: 100},
                    {
                        field: 'operatetime', title: '操作时间', align: 'left',
                        templet: "<div>{{layui.util.toDateString(d.operatetime,'yyyy-MM-dd HH:mm:ss')}}</div>",
                        width: 200
                    }, {
                    fixed: 'right',
                    title: '操作',
                    toolbar: '#barDemo',
                }
                ]
            ]
        });

        //监听头工具栏事件
        table.on('toolbar(main-table)', function (obj) {
            switch (obj.event) {
                case 'add':
                    layer.open({
                        type: 2,
                        title: '新增退货记录信息',
                        content: '/returngoods/returngoodsPage',
                        area:['500px','410px'],
                        btn:['确定','取消'],
                        yes:function (index,layero) {
                            var iframeWindow = window['layui-layer-iframe'+index];  //弹出层
                            var submit = layero.find('iframe').contents().find("#LAY-front-submit"); //弹出层提交按钮
                            //监听提交
                            iframeWindow.layui.form.on('submit(LAY-front-submit)',function (data) {
                                var field = data.field;
                                $.ajax({
                                    url: '/returngoods/returngoodsAdd',
                                    data: field,
                                    async: false,
                                    cache: false,
                                    success: function (str) {
                                        if(str.code === 0){
                                            table.reload('table-load');
                                        }
                                        layer.msg(str.msg,{icon:str.icon,anim:str.anim,time:1000});
                                    }
                                });
                                layer.close(index);     //关闭弹层
                            });
                            submit.trigger('click');
                        }
                    });
                    break;
                case 'querySearch':
                    var param = $("#param").val();
                    table.reload('table-load', {
                        where: {
                            param: param
                        }
                    });
                    $('#param').val(param);
                    break;
            }
        });

        //监听工具条
        table.on('tool(main-table)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确认要删除吗？',{icon:6,title:'操作确认',btn:['确定','再想想']}, function (index) {
                    $.ajax({
                        url: '/returngoods/returngoodsDelById?id='+data.id,
                        data: null,
                        async: false,
                        cache: false,
                        success: function (str) {
                            if(str.code === 0){
                                table.reload('table-load');
                            }
                            layer.msg(str.msg,{icon:str.icon,anim:str.anim,time:1000});
                        }
                    });
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                layer.open({
                    type: 2,
                    title: '编辑退货记录信息',
                    content: '/returngoods/returngoodsQueryById?id='+data.id,
                    area:['500px','410px'],
                    btn:['确定','取消'],
                    yes:function (index,layero) {
                        var iframeWindow = window['layui-layer-iframe'+index];  //弹出层
                        var submit = layero.find('iframe').contents().find("#LAY-front-submit"); //弹出层提交按钮
                        //监听提交
                        iframeWindow.layui.form.on('submit(LAY-front-submit)',function (data) {
                            var field = data.field;
                            $.ajax({
                                url: '/returngoods/returngoodsEdit',
                                data: field,
                                async: false,
                                cache: false,
                                success: function (str) {
                                    if(str.code === 0){
                                        table.reload('table-load');
                                    }
                                    layer.msg(str.msg,{icon:str.icon,anim:str.anim,time:1000});
                                }
                            });
                            layer.close(index);     //关闭弹层
                        });
                        submit.trigger('click');
                    }
                });
            }
        });
    });
</script>
</html>